package com.alks.function.controller.stockdept.pcfactorystockquery;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RedisLock;
import com.alks.common.aop.RoleCheck;
import com.alks.entity.data.enums.RedisKeyEnum;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CsmDetAddRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CsmDetRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.LotMtlRequest;
import com.alks.function.service.stockdept.pcfactorystockquery.IPackMtlIOService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@ApiRestController("/pcFactorStockQuery")
@Api(value = "仓储部查询",tags = "仓储部-仓储工厂作业-包材入库作业")
@RequiredArgsConstructor
@RoleCheck(prgIds = {"160122"})
public class PackMtlInController {
    private final IPackMtlIOService service;
    private final String slipType="I";

    @GetMapping("/getPackInTempQuery")
    @ApiOperation(value = "待入库明细-查询",tags = "仓储部-仓储工厂作业-包材入库作业")
    public ResponseInfo getPackInTempQuery(){
        return service.getPackTempQuery(slipType);
    }

    @PutMapping("/getPackInDetQuery")
    @ApiOperation(value = "包材入库明细-可条件查询",tags = "仓储部-仓储工厂作业-包材入库作业")
    public ResponseInfo getPackInDetQuery(@RequestBody CsmDetRequest request){
        return service.getPackDetQuery(request,slipType);
    }

    @PutMapping("/getPackInLotMtlQuery")
    @ApiOperation(value = "选择指令材料-分页可条件查询",tags = "仓储部-仓储工厂作业-包材入库作业")
    public ResponseInfo getPackInLotMtlQuery(@RequestBody LotMtlRequest request) {
        return service.getPackLotMtlQuery(request,slipType);
    }

    @PutMapping("/packInTempAdd")
    @ApiOperation(value = "待入库批处理-新增",tags = "仓储部-仓储工厂作业-包材入库作业")
    public ResponseInfo packInTempAdd(@RequestBody@ApiParam("写到这里找我") List<Map<String, String>> request){
        //传入mtlNo和lotNo，如果有多够则传入QTY和REMARK为【多购入库】
        service.packTempAdd(request,slipType);
        return ResponseInfo.ok();
    }

    @PostMapping("/packInTempUp")
    @ApiOperation(value = "待入库明细修改-更新",tags = "仓储部-仓储工厂作业-包材入库作业")
    public ResponseInfo packInTempUp(@RequestParam@ApiParam("序号") String item,
                                      @RequestParam(required = false)@ApiParam("数量") Float qty,
                                      @RequestParam(required = false)@ApiParam("备注") String remark){
        return service.packTempUp(item,qty,remark,slipType);
    }

    @PutMapping("/packInDetAdd")
    @RedisLock(key = "'key:packInLock'+#request.sendNo",expireTime = 1,message = "数据处理中,请稍后重试!")
    @ApiOperation(value = "入库批处理-新增",tags = "仓储部-仓储工厂作业-包材入库作业")
    public ResponseInfo packInDetAdd(@RequestBody@Valid CsmDetAddRequest request){
        return ResponseInfo.ok(service.packDetailAdd(request,slipType));
    }

    @PostMapping("/packInTempDelete")
    @ApiOperation(value = "待入剩料删除-删除",tags = "仓储部-仓储工厂作业-包材入库作业")
    public ResponseInfo packInTempDelete(@RequestBody List<String> item){
        return service.packTempDelete(item,slipType);
    }

    @PostMapping("/packInDetDelete")
    @ApiOperation(value = "包材入库明细删除-删除",tags = "仓储部-仓储工厂作业-包材入库作业")
    public ResponseInfo packInDetDelete(@RequestBody List<Integer> idList){
        return service.packDetDelete(idList,slipType);
    }
}
